package com.aurora.source.center.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;
import com.aurora.source.center.bean.PersonFlowBean;

import butterknife.BindView;

/**
 * @author: ww
 * @description:流程适配器
 * @date: 2018/9/20
 */
public class FlowAdapter extends BaseRecyclerAdapter<PersonFlowBean> {

    private PersonFlowBean selectBean;


    @Override
    public CommonHolder setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent, R.layout.item_flow);
    }

    public void setSelectBean(int selectBean) {
        this.selectBean = getData(selectBean);
        this.selectBean.setSelect(true);
        notifyDataSetChanged();
    }

    public class MyHolder extends CommonHolder<PersonFlowBean> {

        @BindView(R.id.top_dot)
        View topDot;
        @BindView(R.id.bottom_dot)
        View bottomDot;
        @BindView(R.id.tv_flow)
        TextView tvFlow;
        @BindView(R.id.line_left)
        View lineLeft;
        @BindView(R.id.line_right)
        View lineRight;
        public MyHolder(Context context, ViewGroup root, int layoutRes) {
            super(context, root, layoutRes);
        }

        @Override
        public void bindData(final PersonFlowBean personFlowBean, final int positon) {
            tvFlow.setText(personFlowBean.getFlowName());
            lineLeft.setVisibility(View.VISIBLE);
            lineRight.setVisibility(View.VISIBLE);
            if(positon==0){
                lineLeft.setVisibility(View.INVISIBLE);
            }else if(getItemCount()==1){
                lineLeft.setVisibility(View.INVISIBLE);
                lineRight.setVisibility(View.INVISIBLE);
            }else if(positon==getItemCount()-1){
                lineRight.setVisibility(View.INVISIBLE);
            }


            if (personFlowBean.isHavaPermision()) {
                tvFlow.setTextColor(Color.WHITE);
            } else {
                tvFlow.setTextColor(Color.parseColor("#70d497"));
            }

            if (personFlowBean.isSelect()) {
                topDot.setVisibility(View.VISIBLE);
                topDot.setBackgroundColor(Color.WHITE);
                bottomDot.setBackgroundColor(Color.WHITE);
            } else {
                topDot.setVisibility(View.INVISIBLE);
                bottomDot.setBackgroundColor(Color.parseColor("#70d497"));
            }

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (personFlowBean.isHavaPermision()) {
                        if (selectBean != null) {
                            selectBean.setSelect(false);
                        }
                        selectBean = personFlowBean;
                        selectBean.setSelect(true);
                        notifyDataSetChanged();
                    }
                    if (onItemClickListener != null) {
                        onItemClickListener.onClick(positon, personFlowBean);
                    }
                }
            });

        }
    }
}
